package com.ghsc.ghxc.jsb.ui.my.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.my.bean.OrderBean
import com.ghsc.ghxc.jsb.ui.my.bean.OrderDetailBean
import com.ghsc.ghxc.jsb.ui.my.bean.OrderDetailResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.my.activity
 * 类名：OrderListViewModel
 * 创建时间：2024/4/25 10:42
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class OrderListViewModel : BaseViewModel(){
    //订单列表
    var orderListResult = MutableLiveData<BaseListResponse<OrderBean>>()
    fun orderList(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onOrderList(paras) }
            executeListResponse(
                response,
                { orderListResult.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /** 取消订单 **/
    var cancelOrderResult = MutableLiveData<BaseResponse<Any>>()
    fun cancelOrder(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onCancelOrder(paras) }
            executeResponse(
                response,
                { cancelOrderResult.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    /** 提醒发货 **/
    var onTixingFahuo = MutableLiveData<BaseResponse<Any>>()
    fun onTixingFahuo(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onTixingFahuo(paras) }
            executeResponse(
                response,
                { onTixingFahuo.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    /** 确认收货 **/
    var onQuerenShouhuo = MutableLiveData<BaseResponse<Any>>()
    fun onQuerenShouhuo(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onQuerenShouhuo(paras) }
            executeResponse(
                response,
                { onQuerenShouhuo.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    /** 申请退款 **/
    var onShenqingTuikuan = MutableLiveData<BaseResponse<Any>>()
    fun onShenqingTuikuan(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShenqingTuikuan(paras) }
            executeResponse(
                response,
                { onShenqingTuikuan.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /**
     * 订单详情
     * @param oid 订单id
     */
    var orderDetailResult = MutableLiveData<BaseResponse<OrderDetailResult>>()
    fun orderDetail(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onOrderDetail(paras) }
            executeResponse(
                response,
                { orderDetailResult.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    /**
     * 快递追踪
     * @param oid 订单id
     */
    var onOrderDetailKuaidiInfo = MutableLiveData<BaseResponse<Any>>()
    fun onOrderDetailKuaidiInfo(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onOrderDetailKuaidiInfo(paras) }
            executeResponse(
                response,
                { onOrderDetailKuaidiInfo.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

}